package jsyf.oa.dao.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.dao.BaseJdbcDao;
import jsyf.oa.entity.system.Company2BrandEntity;
import jsyf.oa.entity.system.Role2DepartEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * Created by jjx on 2018/5/27.
 */
@Repository
public class Role2DepartDao  extends BaseDao {
    public Role2DepartDao() {
        super.iBaseEntity = new Role2DepartEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, Role2DepartEntity.class);
    }

    public Role2DepartEntity getById(String id){
        return (Role2DepartEntity) super.getIBaseEntityById(id);
    }

    public void insertBatch(String regionId, String provinceIds){
        List<LinkedHashMap<String,Object>> region2ProvinceList = new ArrayList<LinkedHashMap<String,Object>>();
        LinkedHashMap<String,Object> region2ProvinceMap = null;
        List<String> list = BaseJdbcDao.stringToList(provinceIds);
        for (int i = 0; i < list.size(); i++) {
            region2ProvinceMap = new LinkedHashMap<>();
            region2ProvinceMap.put("ID",super.generateKey());
            region2ProvinceMap.put("ROLE_NAME_ID",regionId);
            region2ProvinceMap.put("DEPART_ID",list.get(i));
            region2ProvinceList.add(region2ProvinceMap);
        }
        super.insertBatch("t_sys_role_name_2_depart",region2ProvinceList);
    }
}
